<template>
	<view class="device-manager-layout">
		<!-- 头部统计信息 -->
		<view class="manager-count-box">
			<view class="count-item">
				<text>机具总数(台)</text>
				<text class="count-text">{{dataInfo.deviceTotal}}</text>
			</view>
			<view class="count-bottom">
				<view class="count-item count-item-bottom">
					<text>未绑定(台)</text>
					<text class="count-item-bottom-text">{{dataInfo.unbindTotalCount}}</text>
				</view>
				<view class="count-item count-item-bottom">
					<text>已绑定(台)</text>
					<text class="count-item-bottom-text">{{dataInfo.bindTotalCount}}</text>
				</view>
				<view class="count-item count-item-bottom">
					<text>已激活(台)</text>
					<text class="count-item-bottom-text">{{dataInfo.activateCount}}</text>
				</view>
			</view>
		</view>
		<!-- 头部信息 -->
		<view class="manager-header">
			<text>我的机具数据</text>
			<text>仅显示您旗下的机具数据</text>
		</view>
		<!-- 我的列表 -->
		<view class="manager-card">
			<view class="manager-card-top" @tap="showMyDeviceList">
				<image src="/static/home/device_manager_list_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">我的机具列表</text>
				<view class="manager-card-top-right">
					<text>总{{dataInfo.agentDeviceCount}}台</text>
					<xh-icon icon="icon_jiantou"></xh-icon>
				</view>
			</view>
			<view class="manager-card-line"></view>
			<view class="manager-card-bottom">
				<view class="manager-card-bottom-item">
					<text>已绑定</text>
					<text>{{dataInfo.agentBindCount}}</text>
				</view>
				<view class="manager-card-bottom-item">
					<text>已激活</text>
					<text>{{dataInfo.agentActivateCount}}</text>
				</view>
				<view class="manager-card-bottom-item">
					<text>未划拨</text>
					<text>{{dataInfo.agentCanTransferCount}}</text>
				</view>
			</view>
		</view>
		<!-- 异常代理商和未认证代理商 -->
		<view class="manager-card" style="margin-top: 30rpx;">
			<view class="manager-card-top" @tap="showFailDeviceList">
				<image src="/static/home/agent_yc_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">未/伪激活机具</text>
				<view class="manager-card-top-right">
					<text>总{{dataInfo.abnormalDeviceCount}}台</text>
					<xh-icon icon="icon_jiantou" style="margin-left: auto;"></xh-icon>
				</view>
			</view>
		</view>
		<!-- 运营工具 -->
		<view style="padding: 20rpx 0;font-size: 30rpx;font-weight: bold;">
			<text>运营工具</text>
		</view>
		<view class="manager-card manager-utils">
			<view class="manager-utils-item" @tap="showUtils(1)">
				<image src="/static/home/device_huabo_icon.png" mode="aspectFit"></image>
				<text>机具划拨</text>
			</view>
			<view class="manager-utils-item" @tap="showUtils(2)">
				<image src="/static/home/device_huibo_icon.png" mode="aspectFit"></image>
				<text>机具回拨</text>
			</view>
			<view class="manager-utils-item" @tap="showUtils(3)">
				<image src="/static/home/device_dbmx_icon.png" mode="aspectFit"></image>
				<text>调拨明细</text>
			</view>
			<view class="manager-utils-item" @tap="showUtils(4)">
				<image src="/static/home/device_jsmx_icon.png" mode="aspectFit"></image>
				<text>接收明细</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { onShow } from '@dcloudio/uni-app'
	import { ref } from 'vue'
	import { getDeviceNumStatistics } from '@/common/api/api.js'
	
	const dataInfo = ref({
		deviceTotal: 0,
		bindTotalCount: 0,
		unbindTotalCount: 0,
		activateCount: 0,
		agentDeviceCount: 0,
		agentBindCount: 0,
		agentActivateCount: 0,
		agentCanTransferCount: 0,
		abnormalDeviceCount: 0,
		noActiveNum: 0,
		noBindNum: 0,
		fakeActiveNum: 0
	})
	// 我的机具列表
	const showMyDeviceList = () => {
		uni.navigateTo({
			url: '/pages/home/device-manager/device-list/device-list'
		})
	}
	// 未/伪激活机具列表
	const showFailDeviceList = () => {
		uni.navigateTo({
			url: '/pages/home/unactive-device/unactive-device'
		})
	}
	// 选择运营工具
	const showUtils = (type) => {
		if (type == 1) {
			uni.navigateTo({
				url: '/pages/home/device-manager/device-allocated/device-allocated?type=划拨'
			})
		} else if (type == 2) {
			uni.navigateTo({
				url: '/pages/home/device-manager/device-allocated/device-allocated?type=回拨'
			})
		} else if (type == 3) {
			uni.navigateTo({
				url: '/pages/home/device-manager/device-allocated-record/device-allocated-record'
			})
		} else {
			uni.navigateTo({
				url: '/pages/home/device-manager/device-receive-record/device-receive-record'
			})
		}
	}
	// 获取机具统计数据
	const getHomeData = async () => {
		const res = await getDeviceNumStatistics()
		dataInfo.value = res.result
	}
	onShow(() => {
		getHomeData()
	})
</script>

<style lang="scss" scoped>
	.device-manager-layout {
		background-color: #fff;
		padding: 20rpx 30rpx;
		min-height: 100vh;

		.manager-count-box {
			background-image: url('/static/operate/yy_byjy_bg@2x.png');
			background-size: 100% 100%;
			background-repeat: no-repeat;
			padding: 40rpx;

			.count-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: #fff;
				font-size: 30rpx;

				.count-text {
					font-size: 68rpx;
					margin-top: 10rpx;
				}
			}

			.count-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-top: 30rpx;

				.count-item-bottom {
					font-size: 26rpx;
				}

				.count-item-bottom-text {
					font-size: 40rpx;
					margin-top: 10rpx;
				}
			}
		}

		.manager-header {
			display: flex;
			flex-direction: column;
			padding: 30rpx 0;
			font-size: 30rpx;

			text:nth-child(1) {
				font-weight: bold;
			}

			text:nth-child(2) {
				color: $xh-color-9;
				font-size: 24rpx;
				margin-top: 10rpx;
			}
		}

		.manager-card {
			border: 1px solid #eee;
			border-radius: 20rpx;
			padding: 20rpx;

			.manager-card-top {
				display: flex;
				align-items: center;

				.manager-card-top-text {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 10rpx;
				}

				.manager-card-top-right {
					display: flex;
					align-items: center;
					margin-left: auto;
					color: $xh-color-9;
					font-size: 26rpx;
				}

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.manager-card-line {
				margin: 20rpx 0;
				height: 1px;
				background-color: #eee;
				transform: scaleY(0.5);
			}

			.manager-card-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;

				.manager-card-bottom-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $xh-color-9;
					font-size: 26rpx;

					text:nth-child(2) {
						font-size: 32rpx;
						color: $xh-color-3;
						font-weight: bold;
					}
				}
			}

		}

		.manager-utils {
			display: grid;
			grid-template-columns: repeat(4, 1fr);
			grid-gap: 20rpx;

			.manager-utils-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 26rpx;
				color: $xh-color-6;

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>